package com.mdxl.layer_cj.dao;


import com.mdxl.layer_cj.shiro.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface MybatisDao {

    @Insert({
        "insert into user(id,username,",
        "password) values(#{id,jdbcType=VARCHAR},#{username,jdbcType=VARCHAR},",
        "#{password,jdbcType=VARCHAR})"
    })
    int add(User user);

    @Delete({
        "delete from user where id =#{id,jdbcType=VARCHAR}"
    })
    int deleteUser(@Param("id")String id);

    @Update({
            "update user set username = #{username,jdbcType=VARCHAR}"
    })
    int updateUser(@Param("username")String username);


    @Select({
            "select id,username,password from user"
    })
    @Results({
            @Result(column = "id",property = "id",jdbcType = JdbcType.VARCHAR,id = true),
            @Result(column = "username",property = "username",jdbcType = JdbcType.VARCHAR),
            @Result(column = "password",property = "password",jdbcType = JdbcType.VARCHAR)
    })
    List<User> getUserList();

    @Select({
            "select id,username,password from user where id =#{id,jdbcType=VARCHAR}"
    })
    @Result(column = "password",property = "password",jdbcType = JdbcType.VARCHAR)
    User getOneUser(@Param("id")String id);


    @InsertProvider(type = MybatisSqlProvider.class,method = "insertUser")
    int insertUser(User user);
}
